<?php
namespace app\index\controller;

use app\common\controller\HomeBase;
use app\common\model\Weijump as WeijumpModel;

class Jumpurl extends HomeBase
{
    protected $weijump_model;

    protected function _initialize(){
        parent::_initialize();
        $this->weijump_model = new WeijumpModel;
    }

    public function index($tok){
        $url = $this->weijump_model->where('id',$tok)->value('encode_url');
        $result = httpRequest($url);
        $pattern = '/try\{getOpenLink\(([\s\S]+?)\);\}catch\(e\)\{\}/';
        preg_match($pattern,$result,$matches);
        $arr = json_decode($matches[1],true);
        if($arr['errcode'] == 0){
            $link = $arr['openlink'];
            $this->assign('link',$link);
            return $this->fetch();
        }else{
            return false;
        }
        
    }
}